package com.kool.kadmin.system.controller;

import com.kool.kadmin.common.bean.ListResult;
import com.kool.kadmin.common.bean.PageListResult;
import com.kool.kadmin.common.bean.Result;
import com.kool.kadmin.system.bean.SysRoleDo;
import com.kool.kadmin.system.request.*;
import com.kool.kadmin.system.service.RoleService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 角色管理
 *
 * @author luyu
 */
@RestController
public class RoleController {
    @Resource
    private RoleService roleService;

    /**
     * 新增角色
     *
     * @return
     */
    @RequestMapping("/role/add")
    public Result add(@Valid @RequestBody AddRoleReq request) {
        return roleService.add(request);
    }

    /**
     * 修改角色
     *
     * @return
     */
    @RequestMapping("/role/modify")
    public Result modify(@Valid @RequestBody ModifyRoleReq request) {
        return roleService.modify(request);
    }

    /**
     * 删除角色
     *
     * @return
     */
    @RequestMapping("/role/delete")
    public Result delete(@Valid @RequestBody DeleteRoleReq request) {
        return roleService.delete(request);
    }

    /**
     * 分页查询角色
     *
     * @return
     */
    @RequestMapping("/role/get_page")
    public PageListResult<SysRoleDo> getPage(@Valid @RequestBody GetRolePageReq request) {
        return roleService.getPage(request);
    }

    /**
     * 绑定用户角色
     *
     * @return
     */
    @RequestMapping("/role/bind_user_role")
    public Result bindUserRole(@Valid @RequestBody BindUserRoleReq request) {
        return roleService.bindUserRole(request);
    }

    /**
     * 查询所有角色
     *
     * @return
     */
    @RequestMapping("/role/get_all_roles")
    public ListResult<SysRoleDo> getAllRoles() {
        return roleService.getAllRoles();
    }

    /**
     * 查询用户角色
     *
     * @return
     */
    @RequestMapping("/role/get_user_roles")
    public ListResult<SysRoleDo> getUserRoles(@Valid @RequestBody GetUserRolesReq request) {
        return roleService.getUserRoles(request);
    }
}
